Command.js ➔ ???   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 72

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
nc 1
nop 2
dl 0
loc 72
cc 1
rs 9.102

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
/**
2
 * An abstract class, used to append commands to a register. This class has to be extended
3
 * @abstract
4
 * @class Command
5
 */
6
class Command {
7
    /**
8
     * Creates an instance of Command.
9
     * @param {string} [name=null] The command's name
0 ignored issues
show
Documentation introduced by
The parameter name=null does not exist. Did you maybe forget to remove this comment?
Loading history...
10
     * @param {FisherRegister} [register=null] The command's register
0 ignored issues
show
Documentation Bug introduced by
The parameter register=null does not exist. Did you maybe mean register instead?
Loading history...
11
     * @memberof Command
12
     */
13
  constructor (name, register) {
14
        /**
15
         * The command's name
16
         * @type {string}
17
         * @name Command#name
18
         * @default null
19
         */
20
    this.name = name
21
        /**
22
         * The command's name
23
         * @type {string}
24
         * @name Command#register
25
         * @default null
26
         */
27
    this.register = register
28
        /**
29
         * A regPattern, to match with the command suffixe
30
         * @type {RegExp}
31
         * @name Command#regPattern
32
         * @default null
33
         */
34
    this.regPattern = null
35
        /**
36
         * A patterncallback to match with middleware
37
         * @type {patternCallback}
38
         * @name Command#patternCallback
39
         * @default null
40
         */
41
    this.patternCallback = null
42
        /**
43
         * The perm(s) required to send a invalid permission fisher code
44
         * @type {(string|string[])}
45
         * @name Command#discordSpecialPerms
46
         * @default ["SEND_MESSAGES"]
47
         */
48
    this.discordSpecialPerms = ['SEND_MESSAGES']
49
        /**
50
         * The perm(s) required to execute the command
51
         * @type {(string|string[])}
52
         * @name Command#discordPermRequired
53
         * @default []
54
         */
55
    this.discordPermRequired = []
56
        /**
57
         * The channel type(s) where the command can be executed
58
         * @type {(string|string[])}
59
         * @name Command#channelType
60
         * @default [dm,"group","text"]
61
         */
62
    this.channelType = ['dm', 'group', 'text']
63
        /**
64
         * An object to store data for middlewares, or for commands
65
         * @type {Object}
66
         * @name Command#locales
67
         * @default Object()
68
         */
69
    this.locales = {}
70
        /**
71
         * An alias or an array of alias for the command
72
         * @type {(string|string[])}
73
         * @name Command#aliases
74
         * @default null
75
         */
76
    this.aliases = null
77
        /**
78
         * If true, a fisherPromiseCallback is passed to the execute function instead of a fisherCallback
79
         * @type {boolean}
80
         * @name Command#isPromise
81
         * @default false
82
         */
83
    this.isPromise = false
84
  }
85
    /**
86
     *
87
     *
88
     * @param {fisherRequest} req The command's request
89
     * @param {fisherResponse} res The command's response
90
     * @param {Promise.resolve} [resolve] (Only if isPromise is set to "true") A Promise.resolve function. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Objets_globaux/Promise/resolve
91
     * @param {Promise.reject} [reject] (Only if isPromise is set to "true") A Promise.reject function. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/reject
92
     * @memberof Command
93
     */
94
  execute (req, res, resolve, reject) {
0 ignored issues
show
Unused Code introduced by
The parameter reject is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter res is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter req is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter resolve is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
95
96
  }
97
}
98
module.exports = Command
99